package com.xywy.common.greendao;

import java.util.Map;

import android.database.sqlite.SQLiteDatabase;

import com.xywy.me.bean.User;
import com.xywy.me.dao.UserDao;
import com.xywy.wjk.bean.BloodPressureData;
import com.xywy.wjk.bean.WeightData;
import com.xywy.wjk.dao.BloodPressureDataDao;
import com.xywy.wjk.dao.WeightDataDao;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;

/**
 * {@inheritDoc}
 * 
 * @see de.greenrobot.dao.AbstractDaoSession
 */
public class DaoSession extends AbstractDaoSession {

    private final DaoConfig userDaoConfig;
    private final DaoConfig bloodPressureDataDaoConfig;
    private final DaoConfig weightDataDaoConfig;

    private final UserDao userDao;
    private final BloodPressureDataDao bloodPressureDataDao;
    private final WeightDataDao weightDataDao;

    public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
            daoConfigMap) {
        super(db);

        userDaoConfig = daoConfigMap.get(UserDao.class).clone();
        userDaoConfig.initIdentityScope(type);

        bloodPressureDataDaoConfig = daoConfigMap.get(BloodPressureDataDao.class).clone();
        bloodPressureDataDaoConfig.initIdentityScope(type);

        weightDataDaoConfig = daoConfigMap.get(WeightDataDao.class).clone();
        weightDataDaoConfig.initIdentityScope(type);

        userDao = new UserDao(userDaoConfig, this);
        bloodPressureDataDao = new BloodPressureDataDao(bloodPressureDataDaoConfig, this);
        weightDataDao = new WeightDataDao(weightDataDaoConfig, this);

        registerDao(User.class, userDao);
        registerDao(BloodPressureData.class, bloodPressureDataDao);
        registerDao(WeightData.class, weightDataDao);
    }
    
    public void clear() {
        userDaoConfig.getIdentityScope().clear();
        bloodPressureDataDaoConfig.getIdentityScope().clear();
        weightDataDaoConfig.getIdentityScope().clear();
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public BloodPressureDataDao getBloodPressureDataDao() {
        return bloodPressureDataDao;
    }

    public WeightDataDao getWeightDataDao() {
        return weightDataDao;
    }

}